<?php
namespace App\Model\Attend;

use App\Model\Base;
use App\Model\Device\Device;
use App\Model\Face\Face;
use App\Model\System\WxConfig;

class LeaveSend extends Base{
    public $tableName = "mymk_leave_send";

    /**
     * 通过条件获取数据库里面的设备
     * @auth   xiaozhi
     * @param  array   $condition [description]
     * @return [type]             [description]
     */
    public function getLogStaff($field = '*', $where = [], $order = ['A.id', 'desc']) {
        $faceObj = new Face();
        $wxconfigObj = new WxConfig();
        $this->withTotalCount()
            ->field($field)
            ->order($order[0], $order[1])
            ->alias('A')
            ->join($faceObj->tableName().' as B','A.faceid=B.id','LEFT')
            ->join('mymk_leave_log as C','A.leavelogid=C.id','LEFT')
            ->join($wxconfigObj->tableName().' as D','A.companyid=D.companyid','LEFT')
            ->where($where)
            ->all();

        $lists = $this->lastQueryResult()->getResult();

        // $list = $lastResult->getResult();
        return $lists;
    }

    public function getSendStaffOne(string $field = '*', array $where = []){
        $this
            ->field($field)
            ->alias('A')
            ->join('mymk_face as B', 'A.faceid=B.id', 'LEFT')
            ->where($where)
            ->get();
        $result = $this->lastQueryResult()->getResult();
        if(empty($result)){
            return false;
        }else{
            return $result[0];
        }
    }

    /**
     * 通过条件获取数据库里面的设备
     * @auth   xiaozhi
     * @param  array   $condition [description]
     * @return [type]             [description]
     */
    public function getSendStaff($field = '*', $where = [], $order = ['A.id', 'desc']) {

        $this->withTotalCount()
            ->field($field)
            ->order($order[0], $order[1])
            ->alias('A')
            ->join('mymk_face as B','A.faceid=B.id','LEFT')
            ->where($where)
            ->all();

        $lists = $this->lastQueryResult()->getResult();

        // $list = $lastResult->getResult();
        return $lists;
    }
}